﻿<?php
/**
 * 管理用户题目界面
 *
 * @author kinet <380511703@qq.com>
 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
 */

session_start();
require_once( 'path.php' );
require_once( SOJ_ROOT.'/include/function/lib.php');
require_once('Pager.php');

$tpl = new my_smarty();

//若未登录,则重定向到登录界面
if( empty($_SESSION['admin']) ){

	$_SESSION['success_message'] = 'do not login yet , '.$_SESSION['admin'];
	header( 'Location:../manager/manager_login.php' );
	exit ;
}
//处理由其他页面保存在会话中的错误信息
if( !empty($_SESSION['errors']) ){

	$tpl->assign( 'errors' , $_SESSION['errors']  );
	//清除之前的错误信息
	unset( $_SESSION['errors'] );
}
$tpl->assign('admin', $_SESSION['admin']);
$request=$_POST;
if(empty($request['search'])){
 header( 'Location:../manager/manager_problem.php' );
 exit;
}
$search=$request['search'];
if(empty($search)){
 
 header( 'Location:../manager/manager_problem.php' );
 exit;

}
$flag=0;
if($request['option']==="no"){
   try{
   
     $db = db_connect();
	 $problems = problem_process::get_by_no( $db,$search );
	 
   }    
    catch(Exception $e){
	}	
}
else if($request['option']==="source"){
try{
   
     $db = db_connect();
	 $problems = problem_process::get_by_source( $db,$search );
   }    
    catch(Exception $e){
	}	
}
else{
  header( 'Location:../manager/manager_problem.php' );
  exit;
}
try{
	
	if ( empty($problems) ){
		header( 'Location:../manager/manager_problem.php' );
        exit;
	}
	//动态获得结果数组的键名
	$titles = array_keys( $problems[0] );
	$problem_num = count( $problems );

	//此配置应该可以由配置文件读出
	$params = array(
    		'itemData' => $problems,
    		'perPage' => 30,
    		'delta' => 8,
    		'append' => true,
    		'clearIfVoid' => false,
    		'urlVar' => 'entrant',
    		'useSessions' => true,
    		'closeSession' => true,
    		'mode'  => 'Jumping',
	);

	$pager = & Pager::factory($params);
	$page_data = $pager->getPageData();
	$links = $pager->getLinks();

//	$selectBox = $pager->getPerPageSelectBox();

	$tpl->assign( 'titles' , $titles );
	$tpl->assign( 'problem_num' , $problem_num );
	$tpl->assign( 'problems' , $page_data );
	$tpl->assign( 'links' , $links['all'] );
    $tpl->assign( 'isnotempty' , true );
	$tpl->display('manager_problem.tpl');

}catch(Exception $e){

	exception_handle( $e );
}




